package hn.sigit.model.hnd.ladmshadow;

import java.io.Serializable;
import javax.persistence.*;

import hn.sigit.model.ladm.administrative.LA_BAUnitType;

@Entity
@org.hibernate.annotations.Proxy(lazy=false)
@Table(name="BAUnit", schema="ladmshadow")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorValue("BAUnit")
public class BAUnit extends AssociationInfo implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private long uID;
	private Party baParty;
	private String name;
	private LA_BAUnitType type;
	private java.util.Set<SpatialSource> spatialSources = new java.util.HashSet<SpatialSource>();
	private java.util.Set<RRR> rrr = new java.util.HashSet<RRR>();
	private java.util.Set<RequiredRelationshipBAUnit> baunits1requiredrelationshipbaunits = new java.util.HashSet<RequiredRelationshipBAUnit>();
	private java.util.Set<SpatialUnit> spatialUnits = new java.util.HashSet<SpatialUnit>();
	private java.util.Set<AdministrativeSource> adminSources = new java.util.HashSet<AdministrativeSource>();
	private java.util.Set<RequiredRelationshipBAUnit> baunits2requiredrelationshipbaunits = new java.util.HashSet<RequiredRelationshipBAUnit>();
	
	public BAUnit() {
	}
	
	
	@Id
	@Column(name="ID", nullable=false)
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="shw_baunit_id_gen")
	@SequenceGenerator(name="shw_baunit_id_gen", sequenceName="shw_baunit_id_seq", allocationSize=1)
	public long getuID() {
		return uID;
	}
	public void setuID(long value) {
		this.uID = value;
	}
	@Transient
	public long getORMID() {
		return getuID();
	}
	
	@Column(name="Name", nullable=true, length=255)
	public String getName() {
		return name;
	}
	public void setName(String value) {
		this.name = value;
	}
	
	@Column(name="Type", nullable=true)
	@Enumerated(EnumType.STRING)
	public LA_BAUnitType getType() {
		return type;
	}
	public void setType(LA_BAUnitType value) {
		this.type = value;
	}
	
	@ManyToMany(targetEntity=SpatialSource.class)	
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.LOCK})	
	@JoinTable(name="SpatialSource_BAUnit", schema="ladmshadow", joinColumns={ @JoinColumn(name="BAUnitID") }, inverseJoinColumns={ @JoinColumn(name="SpatialSourceSourceID") })	
	@org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.TRUE)	
	public java.util.Set<SpatialSource> getSpatialSources() {
		return spatialSources;
	}
	public void setSpatialSources(java.util.Set<SpatialSource> value) {
		this.spatialSources = value;
	}
	
	@OneToMany(mappedBy="baunit", targetEntity=RRR.class)
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.LOCK})
	@org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.TRUE)
	public java.util.Set<RRR> getRrr() {
		return rrr;
	}
	public void setRrr(java.util.Set<RRR> value) {
		this.rrr = value;
	}
	
	@OneToMany(mappedBy="baunits2baunit", targetEntity=RequiredRelationshipBAUnit.class)	
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.LOCK})	
	@org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.TRUE)	
	public java.util.Set<RequiredRelationshipBAUnit> getBaunits1requiredrelationshipbaunits() {
		return baunits1requiredrelationshipbaunits;
	}
	public void setBaunits1requiredrelationshipbaunits(java.util.Set<RequiredRelationshipBAUnit> value) {
		this.baunits1requiredrelationshipbaunits = value;
	}
	
	@OneToOne(targetEntity=Party.class, fetch=FetchType.LAZY)
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.LOCK})	
	@JoinColumns({ @JoinColumn(name="PartyID") })	
	@org.hibernate.annotations.LazyToOne(value=org.hibernate.annotations.LazyToOneOption.NO_PROXY)	
	public Party getBaParty() {
		return baParty;
	}
	public void setBaParty(Party value) {
		this.baParty = value;
	}
	
	@ManyToMany(targetEntity=SpatialUnit.class)
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.LOCK})	
	@JoinTable(name="BAUnit_SpatialUnit", schema="ladmshadow", joinColumns={ @JoinColumn(name="BAUnitID") }, inverseJoinColumns={ @JoinColumn(name="SpatialUnitID") })	
	@org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.TRUE)	
	public java.util.Set<SpatialUnit> getSpatialUnits() {
		return spatialUnits;
	}
	public void setSpatialUnits(java.util.Set<SpatialUnit> value) {
		this.spatialUnits = value;
	}
	
	@ManyToMany(mappedBy="units", targetEntity=AdministrativeSource.class)	
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.LOCK})	
	@org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.TRUE)	
	public java.util.Set<AdministrativeSource> getAdminSources() {
		return adminSources;
	}
	public void setAdminSources(java.util.Set<AdministrativeSource> value) {
		this.adminSources = value;
	}
	
	@OneToMany(mappedBy="baunits1baunit", targetEntity=RequiredRelationshipBAUnit.class)	
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.LOCK})	
	@org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.TRUE)	
	public java.util.Set<RequiredRelationshipBAUnit> getBaunits2requiredrelationshipbaunits() {
		return baunits2requiredrelationshipbaunits;
	}
	public void setBaunits2requiredrelationshipbaunits(java.util.Set<RequiredRelationshipBAUnit> value) {
		this.baunits2requiredrelationshipbaunits = value;
	}
	
	
	@Transient
	public BAUnit[] getBaunits1baunits() {
		java.util.ArrayList lValues = new java.util.ArrayList(5);
		for(java.util.Iterator lIter = baunits1requiredrelationshipbaunits.iterator();lIter.hasNext();) {
			lValues.add(((RequiredRelationshipBAUnit)lIter.next()).getBaunits1baunit());
		}
		return (BAUnit[])lValues.toArray(new BAUnit[lValues.size()]);
	}
	
	public void removeBaunits1baunit(BAUnit aBaunits1baunit) {
		RequiredRelationshipBAUnit[] lBaunits1requiredrelationshipbaunits = (RequiredRelationshipBAUnit[])baunits1requiredrelationshipbaunits.toArray(new RequiredRelationshipBAUnit[baunits1requiredrelationshipbaunits.size()]);
		for(int i = 0; i < lBaunits1requiredrelationshipbaunits.length; i++) {
			if(lBaunits1requiredrelationshipbaunits[i].getBaunits1baunit().equals(aBaunits1baunit)) {
				baunits1requiredrelationshipbaunits.remove(lBaunits1requiredrelationshipbaunits[i]);
			}
		}
	}
	
	@Transient
	public BAUnit[] getBaunits2baunits() {
		java.util.ArrayList lValues = new java.util.ArrayList(5);
		for(java.util.Iterator lIter = baunits2requiredrelationshipbaunits.iterator();lIter.hasNext();) {
			lValues.add(((RequiredRelationshipBAUnit)lIter.next()).getBaunits2baunit());
		}
		return (BAUnit[])lValues.toArray(new BAUnit[lValues.size()]);
	}
	
	public void removeBaunits2baunit(BAUnit aBaunits2baunit) {
		RequiredRelationshipBAUnit[] lBaunits2requiredrelationshipbaunits = (RequiredRelationshipBAUnit[])baunits2requiredrelationshipbaunits.toArray(new RequiredRelationshipBAUnit[baunits2requiredrelationshipbaunits.size()]);
		for(int i = 0; i < lBaunits2requiredrelationshipbaunits.length; i++) {
			if(lBaunits2requiredrelationshipbaunits[i].getBaunits2baunit().equals(aBaunits2baunit)) {
				baunits2requiredrelationshipbaunits.remove(lBaunits2requiredrelationshipbaunits[i]);
			}
		}
	}
	
	public void addBaunits2baunit(RequiredRelationshipBAUnit aRequiredRelationshipBAUnit, BAUnit aBaunits2baunit) {
		aRequiredRelationshipBAUnit.setBaunits2baunit(aBaunits2baunit);
		baunits2requiredrelationshipbaunits.add(aRequiredRelationshipBAUnit);
	}
	
	public RequiredRelationshipBAUnit getrequiredrelationshipbaunitByBaunits2baunit(BAUnit aBaunits2baunit) {
		RequiredRelationshipBAUnit[] lBaunits2requiredrelationshipbaunits = (RequiredRelationshipBAUnit[])baunits2requiredrelationshipbaunits.toArray(new RequiredRelationshipBAUnit[baunits2requiredrelationshipbaunits.size()]);
		for(int i = 0; i < lBaunits2requiredrelationshipbaunits.length; i++) {
			if(lBaunits2requiredrelationshipbaunits[i].getBaunits2baunit().equals(aBaunits2baunit)) {
				return lBaunits2requiredrelationshipbaunits[i];
			}
		}
		return null;
	}

	public void addBaunits1baunit(RequiredRelationshipBAUnit aRequiredRelationshipBAUnit, BAUnit aBaunits1baunit) {
		aRequiredRelationshipBAUnit.setBaunits1baunit(aBaunits1baunit);
		baunits1requiredrelationshipbaunits.add(aRequiredRelationshipBAUnit);
	}
	
	public RequiredRelationshipBAUnit getrequiredrelationshipbaunitByBaunits1baunit(BAUnit aBaunits1baunit) {
		RequiredRelationshipBAUnit[] lBaunits1requiredrelationshipbaunits = (RequiredRelationshipBAUnit[])baunits1requiredrelationshipbaunits.toArray(new RequiredRelationshipBAUnit[baunits1requiredrelationshipbaunits.size()]);
		for(int i = 0; i < lBaunits1requiredrelationshipbaunits.length; i++) {
			if(lBaunits1requiredrelationshipbaunits[i].getBaunits1baunit().equals(aBaunits1baunit)) {
				return lBaunits1requiredrelationshipbaunits[i];
			}
		}
		return null;
	}
	
	public String toString() {
		return super.toString();
	}
}
